const app = getApp()
Page({
  data: {
    image1path: '',
    ufacedata: {},//识别记录
    page: 1,
    isBottom: false,//是否加载
    isphotodata: false,//相册是否有数据
    nodata: false,//显示没有数据
    showbottom: false,//显示到底部
    loadingHidden: false,//代表出现加载
    user_id: '',
    parentrole: 'hide',//家长首页
    classmaster: 'hide',//班主任标志
    isbind: false,
    userInfo: [],
    dispaly: 'hide',
    content: '',
    jia: 'show',
    role: '',//3为家长角色 1为班主任
  },
  //获取数据列表 某孩子或者家长的人脸识别数据 ，如果是老师则用自己的id
  getLocation: function (options) {
    var page = options;
    var that = this;
    var user_id=0;
    var openid = app.globalData.openid;
    var link = app.globalData.schlink;
    if (app.globalData.bindInfo){
      if (app.globalData.bindInfo.user_type==1){
        var user_id = app.globalData.bindInfo.user_id;
      }
      if (app.globalData.bindInfo.user_type == 3) {
        var user_id = app.globalData.bindInfo.stu_id;//学生账号id才行
      }
    }
    wx.request({
      url: getApp().globalData.baseUrl + 'ufacelist',
      data: {
        user_id: user_id,
        link: link,
        openid: openid,
        page: page,
        limit: 10
      },
      method: "get",
      header: {},
      success: function (res) {
        // console.log(res);return;
        if (res.data.code == 200) {
          var resultdata = res.data.data.data;
          for (var index in resultdata) {
            var image1path = resultdata[index]['base64'];
            resultdata[index]['base64'] = image1path.replace(/[\r\n]/g, "");;
          }
          var count = res.data.data.count;
          if (count > page * 10) {
            that.setData({isBottom:true});//多于10条数据
          } else {
            that.setData({ isBottom: false });
          }
          if (resultdata.length > 0) {
            that.setData({ isphotodata: true });
            that.setData({ count: count });
            var arr = [];
            if (page > 1) {
              var ufacedata = that.data.ufacedata;
              arr = ufacedata.concat(resultdata);
              that.setData({ ufacedata: arr });
            } else {
              that.setData({ ufacedata: resultdata });
            }
          } else {
            that.setData({ nodata: true });//没有数据
            that.setData({ isphotodata: true });
          }
        }
        that.setData({ loadingHidden: true });
      }
    })
  },
  //查看详情
  seedetail: function (e) {
    var dataId = e.currentTarget.dataset.idx;
    wx.navigateTo({
      url: '../classcard/photodetail?id=' + dataId
    })
  },

  //初加载 家长角色有孩子人脸识别数据 ，老师是自己的数据
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: "人脸识别数据"
    })
    var that = this;
    if (app.globalData.bindInfo) {
      that.getLocation(1);//获取人脸记录列表
      this.setData({parentrole:'show' });
      this.setData({
        isbind: true,
        user_id: app.globalData.bindInfo.user_id
      })
      if (app.globalData.bindInfo.user_type == 1) {
        this.setData({//班主任
          role: 1
        })
      }
      if (app.globalData.bindInfo.classmaster > 0) {
        this.setData({
          classmaster: 'show'
        })
      }
      if (app.globalData.bindInfo.user_type == 3) {
        this.setData({
          role: 3
        })
      }
    } else {
      wx.navigateTo({
        url: '../binding/binding'
      })
    }

    if (app.globalData.userInfo) {

    } else {
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  onReady: function () {
  },
  onShow: function () {
    this.setime();
    if (app.globalData.bindInfo) {
      this.setData({parentrole: 'show' });
      this.setData({
        isbind: true,
        user_id: app.globalData.bindInfo.user_id
      })
      if (app.globalData.bindInfo.user_type == 1) {
        this.setData({//班主任
          role: 1
        })
      }
      if (app.globalData.bindInfo.classmaster > 0) {
        this.setData({
          classmaster: 'show'
        })
      }
      if (app.globalData.bindInfo.user_type == 3) {
        this.setData({
          role: 3
        })
      }
    } else {
      wx.redirectTo({
        url: '../binding/binding'
      })
    }
   
  },
  setime: function (options) {
    var that = this;
    var timer;
    timer = setTimeout(function () {
      that.getLocation(1);//获取人脸记录列表
    }, 5000);
  },
  onHide: function () {
  },
  onUnload: function () {
  },
  onPullDownRefresh: function () {
  },
  // onReachBottom: function () {
  //   var data = this.data.photolistdata;
  //   var count = this.data.count;
  //   var isBottom = this.data.isBottom;
  //   if (!isBottom) {
  //     this.setData({ showbottom: true });
  //     return;
  //   }
  //   var that = this;
  //   var page = this.data.page;
  //   page = page + 1;
  //   that.getLocation(page);
  // },
  onShareAppMessage: function () {
  }
})